const fwlog = require('@/static/core/fwlog.js');
const wechat = {
  //权限列表 https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/authorize.html
  permission: function (scope, successcallback, failcallback, completecallback){
    uni.getSetting({
      success(res){
        fwlog.debug(res);
        if (!res.authSetting[scope]){
          //未授权
          uni.authorize({
            scope: scope,
            success(res){
              fwlog.debug(res);
              //授权成功
              successcallback && successcallback();
            },
            fail(res){
              fwlog.debug(res);              
              failcallback && failcallback();
            },
            complete(res){
              fwlog.debug(res);
              completecallback && completecallback();
            }
          })
        }else{
          //已授权
          successcallback && successcallback();
        }
      },
      fail(res){
        //获取权限列表失败
        fwlog.debug(res);
      },
      complete(res){
        //获取权限列表完成
        fwlog.debug(res);
      }
    })
  }
}
module.exports = wechat;